/*
 * Copyright (c) 2023 Huawei Technologies Co., Ltd.
 * openUBMC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#ifndef _INTERFACE_CHIP_H_
#define _INTERFACE_CHIP_H_

#include "chip/bus_lock.h"
#include "internal/bus/bus_base/bus.h"
#include "internal/chip/chip_base/chip.h"
#include <device_tree/interface/Chip.h>
#include <mc/core/timer.h>
#include <mc/engine/service.h>
#include <mc/exception.h>

// 扩展读模式
#define EXTEND_READ_MODE 0xffffffff

namespace dev {

class Interface_Chip : public mc::engine::interface<Interface_Chip, gen::Chip> {
public:
    Interface_Chip()  = default;
    ~Interface_Chip() = default;

    // 从variant中加载配置到基类属性
    void from_variant(mc::mutable_dict& csr_object);

    std::vector<uint8_t> BitIORead(uint32_t offset, uint8_t length, uint32_t mask) override;
    void                 BitIOWrite(uint32_t offset, uint8_t length, uint32_t mask,
                                    const std::vector<uint8_t>& buffer) override;
    std::vector<uint8_t> BlockIORead(uint32_t offset, uint32_t length) override;
    void                 BlockIOWrite(uint32_t offset, const std::vector<uint8_t>& buffer) override;
    std::vector<uint8_t> BlockIOWriteRead(const std::vector<uint8_t>& indata,
                                          uint32_t                    read_length) override;
    std::vector<uint8_t> BlockIOComboWriteRead(uint32_t                    write_offset,
                                               const std::vector<uint8_t>& write_buffer,
                                               uint32_t read_offset, uint32_t read_length) override;

    chip_base* m_chip = nullptr;
};

} // namespace dev

#endif // _INTERFACE_CHIP_H_